package com.seedwill.common.query.page;

/**
 * @author 衣奎德
 *
 */
public class APage implements java.io.Serializable {

    protected static final int defaultSize = 15 ;
    
    protected int pageSize;

    protected int count = 0;

    protected int nextPage;

    protected int prevPage;

    protected int firstPage = 1;

    protected int lastPage;

    protected int startPage = 1;

    protected int endPage;

    protected int startIndex = 0;

    protected int pageCount = 0;

    protected int currPage = 1;
    
    public APage(int count , int currPage){
        this(count , currPage , defaultSize);
    }

    public APage(int count, int currPage , int preferSize) {
    	if(0 == preferSize){ preferSize = defaultSize; }
        this.count = count;
        this.currPage = currPage;
        this.pageSize = preferSize;
        
        if (0 == count % preferSize) {
            pageCount = (int) (count / preferSize);
        } else {
            pageCount = (int) (count / preferSize) + 1;
        }
        pageCount = (0 == pageCount) ? 1 : pageCount;
        lastPage = pageCount;
        //
        if (currPage < 1) {
            currPage = 1;
            prevPage = 1;
        } else {
            prevPage = 0 == (currPage - 1) ? 1 : (currPage - 1);
        }
        if (currPage > pageCount) {
            currPage = pageCount;
            nextPage = currPage;
            this.currPage = pageCount;
        } else {
            nextPage = currPage + 1;
        }

        startIndex = currPage * preferSize - preferSize;

        if (pageCount < 11) {
            endPage = pageCount;
        } else {
            if (currPage < 6){
                endPage = 11;
            //else if (currPage >= 6 && currPage <= pageCount - 5) {
            }else if (currPage <= pageCount - 5) {   //modify by zhenggm
                startPage = currPage - 5;
                endPage = currPage + 5;
            } else {
                //startPage = currPage - 10;    
                startPage=pageCount-10; //modify by zhenggm 
                endPage = pageCount;
            }
        }
        
    }

    public int getCount() {
        return count;
    }

    public int getCurrPage() {
        return currPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public int getFirstPage() {
        return firstPage;
    }

    public int getLastPage() {
        return lastPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public int getPageCount() {
        return pageCount;
    }

    public int getPrevPage() {
        return prevPage;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public int getStartPage() {
        return startPage;
    }

    public int getPageSize() {
        return pageSize;
    }

//    public static void main(String[] args){
//        Page page=new Page(159, 10);
//    }
    
}
